#!/bin/bash -ex

DEFAULT_OHOS_REMOTE="ohos_origin"
DEFAULT_OHOS_REMOTE_BRANCH="OpenHarmony_feature_20250702"
DEFAULT_LOCAL_REMOTE="origin"
DEFAULT_LOCAL_BRANCH="OpenHarmony_feature_20250702"

pull_and_sync_repos() {
    local REPO="${1}"
    local OHOS_REMOTE="${2:-${DEFAULT_OHOS_REMOTE}}"
    local OHOS_REMOTE_BRANCH="${3:-${DEFAULT_OHOS_REMOTE_BRANCH}}"
    local LOCAL_REMOTE="${4:-${DEFAULT_LOCAL_REMOTE}}"
    local LOCAL_BRANCH="${5:-${DEFAULT_LOCAL_BRANCH}}"

    echo "Updating repo: ${REPO} ..."

    cd ${REPO}
    git stash
    git fetch ${OHOS_REMOTE}
    git checkout "${LOCAL_BRANCH}"
    git pull
    git reset --hard "${OHOS_REMOTE}/${OHOS_REMOTE_BRANCH}"
    git push --set-upstream "${LOCAL_REMOTE}" "${LOCAL_BRANCH}"

    echo "Done repo: ${REPO}"
}
